package com.example.myapplication.tack_18;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TimePicker;
import android.widget.Toast;

import com.example.myapplication.R;

import java.util.Calendar;

public class ReservationActivity extends AppCompatActivity {
    private ImageView exit;
    private LinearLayout lien1;
    private DatePicker date;
    private int cou = 1;
    private String[] starArray = {"大型汽车", "小型汽车", "大型新能源汽车","小型新能源汽车","普通摩托车","...."};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tack_18_activity_reservation);
        init();
        exit_();
        initSpinner();
        line1_();
    }

    private void line1_() {
        lien1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cou++;
                if(cou %2 == 0){
                    date.setVisibility(View.VISIBLE);
                }else{
                    date.setVisibility(View.GONE);
                }

            }
        });
    }

    private void initSpinner() {
        //声明一个下拉列表的数组适配器
        ArrayAdapter<String> starAdapter = new ArrayAdapter<String>(this, R.layout.item_select, starArray);
        //设置数组适配器的布局样式
        starAdapter.setDropDownViewResource(R.layout.tack_18_item_dropdown);
        //从布局文件中获取名叫sp_dialog的下拉框
        Spinner sp = findViewById(R.id.spinner);
        //设置下拉框的标题，不设置就没有难看的标题了
        sp.setPrompt("车辆类型");
        //设置下拉框的数组适配器
        sp.setAdapter(starAdapter);
        //设置下拉框默认的显示第一项
        sp.setSelection(0);
        //给下拉框设置选择监听器，一旦用户选中某一项，就触发监听器的onItemSelected方法
        sp.setOnItemSelectedListener(new ReservationActivity.MySelectedListener());
    }

    class MySelectedListener implements AdapterView.OnItemSelectedListener {

        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
//            Toast.makeText(ReservationActivity.this,"你的选择是"+starArray[i],Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    }

    private void exit_() {
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ReservationActivity.this.finish();
            }
        });
    }

    private void init() {
        exit = findViewById(R.id.exit);
        lien1 = findViewById(R.id.line1);
        date = findViewById(R.id.date);
    }
}